home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir43 / med300.zip / MEFILE.CLA < prev    next >
Text File  |  1994-02-22  |  35KB  |  658 lines

  1.  
  2. !▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3. !█                                                                       █
  4. !█ MEFILE.CLA                                                            █
  5. !█ File handling functions                                               █
  6. !█                                                                       █
  7. !█ Revision Number: 1                                                    █
  8. !█ Revision Date  : 22-Feb-94                                            █
  9. !█                                                                       █
  10. !█ Revision History                                                      █
  11. !█   1 Created                                                           █
  12. !█                                                                       █
  13. !▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  14.  
  15.              MEMBER('MEMOEDIT')
  16.  
  17. !─────────────────────────────────────────────────────────────────────────
  18. !                            Local Module MAP
  19. !─────────────────────────────────────────────────────────────────────────
  20.   MAP                                            !
  21.     ME_LoadASCII( STRING ), BYTE                 ! Load file into document
  22.     ME_SaveASCII( STRING, USHORT, USHORT ), BYTE ! Save block to file
  23.   .
  24.  
  25. !─────────────────────────────────────────────────────────────────────────
  26. !                           Local Module Data
  27. !─────────────────────────────────────────────────────────────────────────
  28. sFileName    STRING(64)                          ! DOS file name
  29.  
  30. oFile        FILE,PRE(OFI),NAME(sFileName),DRIVER('ASCII')
  31. gRecord        RECORD                            ! Generic DOS File
  32. sLine            STRING(255)                     !
  33.              . .                                 !
  34.  
  35.  
  36. !═════════════════════════════════════════════════════════════════════════
  37. !               Load ASCII file at current cursor position
  38. !═════════════════════════════════════════════════════════════════════════
  39. ME_LoadASCII  FUNCTION( sName )
  40.  
  41.              ! Equates:
  42. eLoadPartial EQUATE('File too big!  Try to load anyway?')
  43.  
  44.              ! Locals:
  45. isInsPos     SHORT                               ! Insertion point
  46. isTxtLen     SHORT                               ! Text length
  47. isOldLen     SHORT                               ! Previous text length
  48.  
  49.  
  50.   CODE
  51.   sFileName = sName                              ! Get filename
  52.   OPEN(oFile)                                    ! Open file
  53.   IF ERRORCODE() THEN RETURN( 0 ).               !
  54.  
  55.   IF BYTES(oFile) > (0.9 * (MED:usMaxChars - MED:usCharacters))
  56.     IF NOT ME_Confirm(eLoadPartial)              ! If whole file only
  57.       CLOSE(oFile)                               !   Close file
  58.       RETURN( 0 )                                !   Return
  59.   . .                                            ! Endif
  60.  
  61.   MED:bbHasChanged = 1                           ! Set modified flag
  62.   isInsPos         = MED:usPosition              ! Set insertion point
  63.   isOldLen         = 0                           ! Clear old length
  64.  
  65.   SET(oFile)                                     ! Set to first line
  66.   LOOP WHILE NOT EOF(oFile)                      ! Loop for each file line
  67.     NEXT(oFile)                                  !   Get file line
  68.     isTxtLen = LEN(CLIP(OFI:gRecord))            !   Calc line length
  69.     IF isInsPos + isTxtLen >= MED:usMaxChars     !   If not enough roon
  70.       BREAK                                      !     Break
  71.     .                                            !   Endif
  72.     ME_InsTxt(isInsPos, isTxtLen, OFI:gRecord)   !   Insert text
  73.     isInsPos += isTxtLen                         !   Move insertion point
  74.     CASE MEU:ubAscImpFmt                         !   ASCII Import type:
  75.       OF eImpRefNone                             !     Convert all CR's to
  76.         ME_InsTxt(isInsPos, 1, CHR(eHRt))        !     to hard returns
  77.         isInsPos += 1                            !
  78.       OF eImpRefPart                             !     Convert 2 or more CR's
  79.         IF isTxtLen = 0 AND isOldLen = 0         !     to hard returns
  80.           ME_InsTxt(isInsPos, 1, CHR(eHRt))      !
  81.         ELSE                                     !
  82.           ME_InsTxt(isInsPos, 1, CHR(' '))       !
  83.         .                                        !
  84.         isInsPos += 1                            !
  85.       OF eImpRefFull                             !     Ignore CR's completely
  86.         ME_InsTxt(isInsPos, 1, CHR(' '))         !
  87.         isInsPos += 1                            !
  88.      .                                           !   End case
  89.      isOldLen = isTxtLen                         !   Save old text length
  90.   .                                              ! End loop
  91.   CLOSE(oFile)                                   ! Close file
  92.   ME_ReformDoc()                                 ! Reformat document
  93.   RETURN( 1 )                                    !
  94.  
  95.  
  96. !═════════════════════════════════════════════════════════════════════════
  97. !                   Save block range to ASCII text file
  98. !═════════════════════════════════════════════════════════════════════════
  99. ME_SaveASCII FUNCTION( sName, usRangeBegin, usRangeEnd )
  100.  
  101.              ! Return:
  102. bbRetVal     BYTE                                ! Status flag
  103.  
  104.              ! Locals:
  105. isLine       SHORT                               ! Line index
  106. isLineStart  SHORT                               ! Line start
  107. isLineEnd    SHORT                               ! Line end
  108. isCodeNdx    SHORT                               ! Code position
  109.  
  110.   CODE
  111.   bbRetVal  = 0                                  ! Clear return value
  112.   sFileName = sName                              ! Assign name
  113.   CREATE(oFile)                                  ! Create new file
  114.   IF ERRORCODE()                                 ! Check for errors
  115.     STOP(ERROR())                                !
  116.     DO Quit                                      !
  117.   .                                              !
  118.   OPEN(oFile)                                    ! Open the file
  119.   IF ERRORCODE()                                 ! Check for errors
  120.     STOP(ERROR())                                !
  121.     DO Quit                                      !
  122.   .                                              !
  123.   isLine      = ME_LineIndex(usRangeBegin)       ! Set initial values
  124.   isLineStart = usRangeBegin                     !
  125.   isLineEnd   = ME_LineEnd(isLine)               !
  126.   LOOP WHILE isLineEnd < usRangeEnd              ! Loop until done
  127.     ME_GetBlock(OFI:sLine, isLineStart, (isLineEnd-isLineStart)+1)
  128.     DO WriteLine                                 !   Write line to file
  129.     isLine += 1                                  !
  130.     isLineStart = ME_LineStart(isLine)           !
  131.     isLineEnd   = ME_LineEnd(isLine)             !
  132.   .                                              !   End loop
  133.   ME_GetBlock(OFI:sLine, isLineStart, (usRangeEnd-isLineStart)+1)
  134.   DO WriteLine                                   ! Take care of last line
  135.   CLOSE(oFile)                                   ! Close file
  136.   bbRetVal = 1                                   ! Set return value
  137.   DO Quit                                        ! Quit
  138.  
  139. !──────────────────────────────────────────────────────────────────────────
  140. Quit         ROUTINE      ! Common exit routine
  141. !──────────────────────────────────────────────────────────────────────────
  142.   ME_SetPage()                                   ! Redisplay page
  143.   ME_ShowPage()                                  !
  144.   RETURN( bbRetVal )
  145.  
  146. !──────────────────────────────────────────────────────────────────────────
  147. WriteLine    ROUTINE      ! Write line to disk
  148. !──────────────────────────────────────────────────────────────────────────
  149.   CASE MEU:ubAscExpFmt                           ! Export format:
  150.     OF eExpKillCode                              !   Remove all format codes
  151.       isCodeNdx = INSTRING(CHR(eHRt), OFI:sLine) !
  152.       IF isCodeNdx                               !
  153.         OFI:sLine = SUB(OFI:sLine, 1, isCodeNdx-1)
  154.       .                                          !
  155.     OF eExpKeepCode                              !   Keep format codes
  156.       ! Nothing to do                            !
  157.   .                                              !
  158.   ADD(oFile)                                     ! Write to file
  159.   IF ERRORCODE() THEN STOP(ERROR()).             !
  160.  
  161.  
  162. !═════════════════════════════════════════════════════════════════════════
  163. !               File selection and drive/directory navigation
  164. !═════════════════════════════════════════════════════════════════════════
  165. ME_PickFile  FUNCTION( sFileSpec )
  166.  
  167.              ! Return:
  168. sRetVal      STRING(64)                          ! Selected filename
  169.  
  170.              ! Screens:
  171. ubRepNdx     BYTE                                ! Repeat index
  172.  
  173. wScreen          SCREEN(14,66),PRE(SCR),COLOR(112)
  174.                    !dimensions=25,80,25,80
  175.                    ROW(1,65)   PAINT(1,2),TRN
  176.                    ROW(2,65)   PAINT(13,2),COLOR(8),TRN
  177.                    ROW(14,1)   PAINT(1,2),TRN
  178.                    ROW(14,3)   PAINT(1,62),COLOR(8),TRN
  179.                    ROW(1,1)    STRING('┌─{10}')
  180.                      COL(55)   STRING('─{9}┐')
  181.                    ROW(13,1)   STRING('└─{62}┘')
  182.                                REPEAT(11)
  183.                    ROW(2,1)      STRING('│')
  184.                    ROW(2,64)     STRING('│')
  185.                                .
  186. ssPath             ROW(1,13)   STRING(41),COLOR(112)
  187.                                REPEAT(10,4),EVERY(1,15),INDEX(ubRepNdx)
  188.                    ROW(3,3)      POINT(1,15),USE(?Point),COLOR(78)
  189. ssName               COL(4)      STRING(13)
  190.                                .
  191. ssULArrow          ROW(3,2)    STRING(1),COLOR(126)
  192. ssURArrow            COL(63)   STRING(1),COLOR(126)
  193. ssLLArrow          ROW(12,2)   STRING(1),COLOR(126)
  194. ssLRArrow            COL(63)   STRING(1),COLOR(126)
  195.                  .
  196.  
  197.              ! Locals:
  198. eRows         EQUATE(10)                         ! Rows in scroll area
  199. eCols         EQUATE(4)                          ! Columns in scroll area
  200.  
  201. eDOSSubDir   EQUATE(10H)                         ! DOS Sub-directory bit
  202. eDOSVolLabel EQUATE(08H)                         ! DOS Volume label bit
  203.  
  204. qQueue        QUEUE,PRE(QUE)                     ! Scroll table
  205. sSlash          STRING(1)                        !   Directory slash
  206. sName           STRING(8)                        !   File name
  207. sExt            STRING(3)                        !   File extension
  208.               .
  209.  
  210. gDOS1Dir      GROUP,PRE(DOS)                     ! DOS1 LEM Set/NextDir group
  211.                 BYTE,DIM(21)                     !   Reserved
  212. ubAttrib        BYTE                             !   File attribute
  213. isTime          SHORT                            !   File time
  214. isDate          SHORT                            !   File date
  215. ilSize          LONG                             !   File size in bytes
  216. sNameExt        STRING(13)                       !   Filename
  217.               .                                  !
  218.  
  219. gRegisters   GROUP                               ! CPU Registers
  220. usAX           USHORT                            !
  221. usBX           USHORT                            !
  222. usCX           USHORT                            !
  223. usDX           USHORT                            !
  224. usSI           USHORT                            !
  225. usDI           USHORT                            !
  226. usCFlag        USHORT                            !
  227. usFlags        USHORT                            !
  228.              .                                   !
  229.  
  230. gSegRegs     GROUP                               ! CPU Segment Registers
  231. usES           USHORT                            !
  232. usCS           USHORT                            !
  233. usSS           USHORT                            !
  234. usDS           USHORT                            !
  235.              .                                   !
  236.  
  237. ilTopRow     LONG                                ! Top row offset
  238. ubRow        BYTE                                ! Current screen row
  239. ubSavNdx     BYTE                                ! Saved repeat index
  240. ubPeriod     BYTE                                ! Location of '.' in name.ext
  241. sPath        STRING(64)                          ! Current file path
  242. sSavedPath   STRING(64)                          ! Saved file path
  243. sCFileSpec   CSTRING(65)                         ! ASCIIZ file sepc
  244.  
  245. ubFirstDrive BYTE(2)                             ! Lowest logical drive #
  246. ubLastDrive  BYTE                                ! Highest logical drive #
  247. ubDefDrive   BYTE                                ! Default drive #
  248. ubDrive      BYTE                                ! Drive #
  249.  
  250.   CODE
  251.   sCFileSpec = sFileSpec                         ! Copy to ASCIIZ string
  252.   sSavedPath = PATH()                            ! Save current path
  253.   sPath      = PATH()                            ! Set path variable
  254.   OPEN(wScreen)                                  ! Open screen
  255.   SETCURSOR                                      ! Hide cursor
  256.   DO GetDrives                                   ! Get # of logical drives
  257.   DO BuildTable                                  ! Build file list
  258.   DO FirstPage                                   ! Display first page
  259.   ubRepNdx = (ubLastDrive - ubFirstDrive) + 1    !
  260.  
  261.   LOOP                                           ! Loop
  262.     DO Alerts                                    !   Alert hot keys
  263.     SELECT(?Point)                               !   Get keystroke
  264.     ACCEPT                                       !
  265.     CASE KEYCODE()                               !   Process keystroke
  266.       OF EnterKey;  DO Select                    !
  267.       OF EscKey;    sRetVal = ''; DO Quit        !
  268.       OF UpKey;     DO MoveUp                    !
  269.       OF DownKey;   DO MoveDown                  !
  270.       OF PgUpKey;   DO PageUp                    !
  271.       OF PgDnKey;   DO PageDown                  !
  272.       OF CtrlPgUp;  DO FirstPage                 !
  273.       OF CtrlPgDn;  DO LastPage                  !
  274.   . .                                            ! End loop
  275.  
  276. !──────────────────────────────────────────────────────────────────────────
  277. Quit          ROUTINE     ! Clean up and exit function
  278. !──────────────────────────────────────────────────────────────────────────
  279.   CLOSE(wScreen)                                 ! Close screen
  280.   SETPATH(sSavedPath)                            ! Restore original path
  281.   FREE(qQueue)                                   ! Free memory table
  282.   RETURN(sRetVal)                                ! Return filename
  283.  
  284. !──────────────────────────────────────────────────────────────────────────
  285. Alerts        ROUTINE     ! Alert hot keys
  286. !──────────────────────────────────────────────────────────────────────────
  287.   ALERT                                          !
  288.   ALERT(EscKey)                                  !
  289.   ALERT(DownKey)                                 !
  290.   ALERT(UpKey)                                   !
  291.   ALERT(PgUpKey)                                 !
  292.   ALERT(PgDnKey)                                 !
  293.   ALERT(CtrlPgUp)                                !
  294.   ALERT(CtrlPgDn)                                !
  295.  
  296. !──────────────────────────────────────────────────────────────────────────
  297. Select        ROUTINE     ! Process the Enter key
  298. !──────────────────────────────────────────────────────────────────────────
  299.   GET(qQueue, ilTopRow + ubRepNdx)               ! Get file list entry
  300.   IF QUE:sSlash >= 'A' AND QUE:sSlash <= 'Z'     ! If it's a drive
  301.     sPath = QUE:sSlash & ':\'                    !   Change to new drive
  302.     SETPATH(CLIP(sPath))                         !
  303.     DO BuildTable                                !   Build new file list
  304.     DO FirstPage                                 !
  305.     ubRepNdx = (ubLastDrive - ubFirstDrive) + 1  !
  306.   ELSIF QUE:sSlash = '\'                         ! Else if it's a directory
  307.     IF LEN(CLIP(PATH())) = 3                     !   If it's the root
  308.       sPath = CLIP(PATH()) & CLIP(QUE:sName)     !     No backslash needed
  309.     ELSE                                         !   Else
  310.       sPath = CLIP(PATH()) & '\' & CLIP(QUE:sName)!    Append a backslash
  311.     .                                            !   Endif
  312.     IF QUE:sExt                                  !   If there is an extension
  313.       sPath = CLIP(sPath) & '.' & QUE:sExt       !     Append that also
  314.     .                                            !   Endif
  315.     SETPATH(CLIP(sPath))                         !   Change to new directory
  316.     sPath = CLIP(sPath) & '\'                    !   Append a slash
  317.     DO BuildTable                                !   Build new file list
  318.     DO FirstPage                                 !
  319.     ubRepNdx = (ubLastDrive - ubFirstDrive) + 1  !
  320.   ELSE                                           ! Else
  321.     IF LEN(CLIP(PATH())) = 3                     !   If it's the root
  322.       sRetVal = CLIP(PATH()) & CLIP(QUE:sName) | !     Return filename
  323.                 & '.' & CLIP(QUE:sExt)           !   Else
  324.     ELSE                                         !     Return filename
  325.       sRetVal = CLIP(PATH()) & '\' & CLIP(QUE:sName) |
  326.                 & '.' & CLIP(QUE:sExt)           !   Endif
  327.     .                                            !
  328.     DO Quit                                      !   Quit function
  329.   .                                              ! Endif
  330.  
  331. !──────────────────────────────────────────────────────────────────────────
  332. MoveUp        ROUTINE     ! Move up one line
  333. !──────────────────────────────────────────────────────────────────────────
  334.   IF ubRepNdx > 1                                !
  335.     ubRepNdx -= 1                                !
  336.   ELSIF ilTopRow > 1                             !
  337.     ilTopRow -= 1                                !
  338.     DO ShowTable                                 !
  339.   ELSE                                           !
  340.     BEEP                                         !
  341.   .                                              !
  342.  
  343. !──────────────────────────────────────────────────────────────────────────
  344. MoveDown      ROUTINE     ! Move down one line
  345. !──────────────────────────────────────────────────────────────────────────
  346.   IF ilTopRow + ubRepNdx < RECORDS(qQueue)       !
  347.     IF ubRepNdx < eRows * eCols                  !
  348.       ubRepNdx += 1                              !
  349.     ELSE                                         !
  350.       ilTopRow += 1                              !
  351.       DO ShowTable                               !
  352.     .                                            !
  353.   ELSE                                           !
  354.     BEEP                                         !
  355.   .                                              !
  356.  
  357. !──────────────────────────────────────────────────────────────────────────
  358. PageUp        ROUTINE     ! Move to previous page
  359. !──────────────────────────────────────────────────────────────────────────
  360.   IF (ubRepNdx-1) % eRows                        !
  361.     ubRepNdx -= (ubRepNdx-1) % eRows             !
  362.   ELSIF ilTopRow >= eRows * eCols                !
  363.     ilTopRow -= eRows * eCols                    !
  364.     DO ShowTable                                 !
  365.   ELSE                                           !
  366.     BEEP                                         !
  367.   .                                              !
  368.                                                  !
  369. !──────────────────────────────────────────────────────────────────────────
  370. PageDown      ROUTINE     ! Move to next page
  371. !──────────────────────────────────────────────────────────────────────────
  372.   IF (ubRepNdx % eRows) > 0                      !
  373.     ubRepNdx += eRows                            !
  374.     ubRepNdx -= (ubRepNdx % eRows)               !
  375.   ELSIF ilTopRow + eRows * eCols < RECORDS(qQueue)
  376.     ilTopRow += eRows * eCols                    !
  377.     DO ShowTable                                 !
  378.   ELSE                                           !
  379.     BEEP                                         !
  380.   .                                              !
  381.  
  382. !──────────────────────────────────────────────────────────────────────────
  383. FirstPage     ROUTINE     ! Move to first page
  384. !──────────────────────────────────────────────────────────────────────────
  385.   ilTopRow = 0                                   !
  386.   ubRepNdx = 1                                   !
  387.   DO ShowTable                                   !
  388.  
  389. !──────────────────────────────────────────────────────────────────────────
  390. LastPage      ROUTINE     ! Move to last page
  391. !──────────────────────────────────────────────────────────────────────────
  392.   ubRepNdx = eRows                               !
  393.   ilTopRow = RECORDS(qQueue) - eRows * eCols     !
  394.   IF ilTopRow < 0                                !
  395.     ilTopRow = 0                                 !
  396.     ubRepNdx = RECORDS(qQueue)                   !
  397.   .                                              !
  398.   DO ShowTable                                   !
  399.  
  400. !──────────────────────────────────────────────────────────────────────────
  401. ShowTable     ROUTINE     ! Display file list
  402. !──────────────────────────────────────────────────────────────────────────
  403.   ubSavNdx = ubRepNdx                            !
  404.   LOOP ubRepNdx = 1 TO eRows * eCols             !
  405.     CLEAR(qQueue)                                !
  406.     GET(qQueue, ilTopRow + ubRepNdx)             !
  407.     IF QUE:sSlash >= 'A' AND QUE:sSlash <= 'Z'   !
  408.       SCR:ssName = '[Drive ' & QUE:sSlash & ']'  !
  409.     ELSE                                         !
  410.       IF QUE:sExt                                !
  411.         SCR:ssName = QUE:sSlash & CLIP(QUE:sName) & '.' & QUE:sExt
  412.       ELSE                                       !
  413.         SCR:ssName = QUE:sSlash & QUE:sName      !
  414.   . . .                                          !
  415.   ubRepNdx = ubSavNdx                            !
  416.   DO Arrows                                      !
  417.  
  418. !──────────────────────────────────────────────────────────────────────────
  419. BuildTable    ROUTINE     ! Build file list
  420. !──────────────────────────────────────────────────────────────────────────
  421.   FREE(qQueue)                                   !
  422.   LOOP ubDrive = ubFirstDrive TO ubLastDrive-1   !
  423.     CLEAR(qQueue)                                !
  424.     QUE:sSlash = CHR(VAL('A') + ubDrive)         !
  425.     ADD(qQueue)                                  !
  426.   .                                              !
  427.   IF FindFirst(sCFileSpec, gDOS1Dir, 10h) = -1 THEN EXIT.
  428.   LOOP                                           !
  429.     IF FindNext(gDOS1Dir) = -1 THEN BREAK.       !
  430.     IF DOS:sNameExt = '.' OR BAND(DOS:ubAttrib, eDOSVolLabel) THEN CYCLE.
  431.     DO AddRecord                                 !
  432.   .                                              !
  433.   SORT(qQueue, QUE:sExt  )                       !
  434.   SORT(qQueue, QUE:sName )                       !
  435.   SORT(qQueue, QUE:sSlash)                       !
  436.   SCR:ssPath = sPath                             !
  437.  
  438. !──────────────────────────────────────────────────────────────────────────
  439. AddRecord     ROUTINE     ! Add record to file list
  440. !──────────────────────────────────────────────────────────────────────────
  441.   CLEAR(qQueue)                                  !
  442.   IF BAND(DOS:ubAttrib, eDOSSubDir)              ! If entry is a directory
  443.     QUE:sSlash = '\'                             !   Display a slash
  444.   ELSE                                           ! Else
  445.     QUE:sSlash = '<255>'                         !   A blank
  446.   .                                              ! .
  447.   IF DOS:sNameExt = '..'                         ! If parent directory
  448.     QUE:sName = DOS:sNameExt                     !   Need name only
  449.   ELSE                                           ! Else
  450.     ubPeriod = INSTRING('.', DOS:sNameExt, 1)    !   Seperate name & extension
  451.     IF ubPeriod                                  !
  452.       QUE:sName = SUB(DOS:sNameExt, 1, ubPeriod-1)
  453.       QUE:sExt  = SUB(DOS:sNameExt, ubPeriod+1, 3)
  454.     ELSE                                         !
  455.       QUE:sName = DOS:sNameExt                   !
  456.   . .                                            ! Endif
  457.   ADD(qQueue)                                    ! Add to table
  458.  
  459. !──────────────────────────────────────────────────────────────────────────
  460. Arrows        ROUTINE     ! Display table scroll arrows
  461. !──────────────────────────────────────────────────────────────────────────
  462.   SCR:ssULArrow = ' '                            !
  463.   SCR:ssLLArrow = ' '                            !
  464.   IF ilTopRow > 0                                !
  465.     SCR:ssULArrow = ''                          !
  466.   .
  467.   IF ilTopRow + eRows * eCols < RECORDS(qQueue)  !
  468.     SCR:ssLLArrow = ''                          !
  469.   .                                              !
  470.   SCR:ssURArrow = SCR:ssULArrow                  !
  471.   SCR:ssLRArrow = SCR:ssLLArrow                  !
  472.  
  473. !──────────────────────────────────────────────────────────────────────────
  474. GetDrives     ROUTINE     ! Get # of logical drives
  475. !──────────────────────────────────────────────────────────────────────────
  476.   CLEAR(gRegisters)                              ! Save default drive #
  477.   usAX  = 1900H                                  !
  478.   Junk# = Int86X(21H, gRegisters, gRegisters, gSegRegs)
  479.   ubDefDrive = BAND(usAX, 0FFH)                  !
  480.  
  481.   ubLastDrive = 0                                ! Zero drive count
  482.   LOOP                                           ! Loop
  483.     ubLastDrive += 1                             !   Increment drive count
  484.     usDX  = ubLastDrive                          !   Set as default drive
  485.     usAX  = 0E00H                                !
  486.     Junk# = Int86x(21H, gRegisters, gRegisters, gSegRegs)
  487.     usAX  = 1900H                                !   Get new current drive
  488.     Junk# = Int86x(21H, gRegisters, gRegisters, gSegRegs)
  489.     IF BAND(usAX, 0FH) <> ubLastDrive THEN BREAK.! Break if not the same
  490.   .                                              ! End loop
  491.  
  492.   usDX  = ubDefDrive                             ! Set back to default drive
  493.   usAX  = 0E00H                                  !
  494.   Junk# = Int86x(21H, gRegisters, gRegisters, gSegRegs)
  495.  
  496.  
  497. !═════════════════════════════════════════════════════════════════════════
  498. !               Paste text file at current cursor location
  499. !═════════════════════════════════════════════════════════════════════════
  500. ME_PasteFile PROCEDURE
  501.  
  502.   CODE
  503.   sFileName = ME_PickFile('*.*')                 ! Get filename
  504.   IF NOT sFilename THEN RETURN.                  !
  505.   Junk# = ME_LoadASCII( sFileName )              ! Load file
  506.   RETURN
  507.  
  508.  
  509. !═════════════════════════════════════════════════════════════════════════
  510. !                   Copy marked block to text file
  511. !═════════════════════════════════════════════════════════════════════════
  512. ME_Copy2File PROCEDURE
  513.  
  514.              ! Equates:
  515. eSaveTo      EQUATE('Save block to text file:'  )
  516. eOverwrite   EQUATE('Overwrite existing '       )
  517. eFileSaved   EQUATE('Marked block saved to disk')
  518.  
  519.              ! Locals:
  520. bbQuit       BYTE                                ! Quit flag
  521. sMessage     STRING(80)                          ! Message line
  522.  
  523.   CODE
  524.   IF NOT MED:bbBlockShow THEN RETURN.            ! Return if no block
  525.   DO GetFileName                                 ! Get file name
  526.   ME_NormBlock()                                 ! Save to file
  527.   IF ME_SaveASCII(sFileName, MED:isBlockBegin, MED:isBlockEnd)
  528.     OPEN(wStatus)                                !   Display completion message
  529.     MES:ssStatus = CENTER(eFileSaved, SIZE(MES:ssStatus))
  530.     ASK                                          !   Wait for keypress
  531.     MEG:isKeyBuffer = KEYCODE()                  !   Save in buffer
  532.     CLOSE(wStatus)                               !   Close status screen
  533.   .                                              ! Endif
  534.   DO Quit                                        !
  535.  
  536. !──────────────────────────────────────────────────────────────────────────
  537. Quit         ROUTINE      ! Common exit routine
  538. !──────────────────────────────────────────────────────────────────────────
  539.   ME_MarkOff()                                   ! Turn off block marking
  540.   MED:bbBlockShow = 0                            !
  541.   ME_SetPage()                                   !
  542.   ME_ShowPage()                                  !
  543.   RETURN                                         !
  544.  
  545. !──────────────────────────────────────────────────────────────────────────
  546. GetFileName  ROUTINE      ! Get output file name
  547. !──────────────────────────────────────────────────────────────────────────
  548.   bbQuit = 0                                     ! Clear quit flag
  549.   LOOP                                           ! Loop
  550.     sFileName = ME_Entry(eSaveTo)                !   Get file name
  551.     IF NOT sFileName                             !   If no file name
  552.       DO Quit                                    !     Quit
  553.     ELSE                                         !   Else
  554.       OPEN(oFile)                                !     Open file
  555.       IF NOT ERRORCODE()                         !     If file already exists
  556.         CLOSE(oFile)                             !       Ask user to confirm
  557.         IF NOT ME_Confirm(eOverwrite & CLIP(UPPER(sFileName)) & '?', 0) THEN CYCLE.
  558.       .                                          !     Endif
  559.       BREAK                                      !     Break
  560.   . .                                            ! End loop
  561.  
  562.  
  563. !═════════════════════════════════════════════════════════════════════════
  564. !                         Edit an ASCII file
  565. !═════════════════════════════════════════════════════════════════════════
  566. ME_EditFile  PROCEDURE( sName, usBufSize )
  567.  
  568.              ! Equates:
  569. eDefAlloc    EQUATE(4096)                        ! Default edit buffer size
  570. eNotFound    EQUATE('File not found.  Create?')  !
  571. eLoadPartial EQUATE('File too big!  Try to load anyway?')
  572. eLoseChanges EQUATE('Lose changes?')             !
  573.  
  574.              ! Editing screen:
  575. wScreen          SCREEN(25,80),PRE(SCR),AT(1,1),COLOR(27)
  576.                    !dimensions=25,80,25,80
  577.                  .
  578.  
  579.   CODE
  580.   DO Init                                        ! Initialize
  581.   DO LoadFile                                    ! Load file
  582.   DO Edit                                        ! Edit the file
  583.   DO Quit                                        ! Clean-up and exit
  584.  
  585. !──────────────────────────────────────────────────────────────────────────
  586. Init         ROUTINE      ! Initialize the edit buffer
  587. !──────────────────────────────────────────────────────────────────────────
  588.   IF OMITTED(2) THEN usBufSize = 0.              ! Set default value
  589.   usBufSize = ME_Max(usBufSize, eDefAlloc)       ! Set edit buffer size
  590.   OPEN(wScreen)                                  ! Open screen
  591.   IF MED:ulEditBuffer                            ! If current context
  592.     ADD(qDocument, 1)                            !   Save current context
  593.   .                                              ! Endif
  594.   CLEAR(qDocument)                               ! Clear context
  595.   MED:bbAllocFlag  = 1                           ! Set allocation flag
  596.   MED:ulEditBuffer = CMalloc(usBufSize)          ! Allocate buffer
  597.   IF NOT MED:ulEditBuffer                        ! If no memory
  598.     STOP('INSUFFICIENT MEMORY TO EDIT FILE')     !   Warn user
  599.     DO Quit                                      !   and quit
  600.   ELSE                                           ! Else
  601.     MED:usMaxChars = usBufSize                   ! Set edit buffer size
  602.   .                                              ! Endif
  603.   CMemSet(MED:ulEditBuffer, 20H, MED:usMaxChars) ! Clear buffer
  604.   ME_ScrnDefs(ROW(wScreen), COL(wScreen), ROWS(wScreen)-1, COLS(wScreen))
  605.  
  606. !──────────────────────────────────────────────────────────────────────────
  607. LoadFile     ROUTINE      ! Load file into edit buffer
  608. !──────────────────────────────────────────────────────────────────────────
  609.   sFileName = sName                              ! Assign name
  610.   OPEN(oFile)                                    ! Open file
  611.   IF ERRORCODE()                                 ! If not found
  612.     IF NOT ME_Confirm(eNotFound) THEN DO Quit.   !   Ask to create
  613.   ELSE                                           ! Else
  614.     IF BYTES(oFile) > 0.9 * MED:usMaxChars       !   If can't load whole file
  615.       IF NOT ME_Confirm(eLoadPartial)            !     If whole file only
  616.         CLOSE(oFile)                             !       Close file
  617.         DO Quit                                  !       Quit
  618.     . .                                          !   Endif
  619.     CLOSE(oFile)                                 !   Close file
  620.     ME_ReformDoc()                               !   Initialize buffer
  621.     IF NOT ME_LoadASCII(sFileName) THEN DO Quit. !   Load file contents
  622.   .                                              ! Endif
  623.   MED:bbHasChanged = 0                           ! Clear changed flag
  624.  
  625. !──────────────────────────────────────────────────────────────────────────
  626. Edit         ROUTINE      ! Edit the file
  627. !──────────────────────────────────────────────────────────────────────────
  628.   LOOP                                           ! Loop
  629.     ALERT                                        !   Alert completion keys
  630.     ALERT(MEU:isFlSaveKey)                       !
  631.     ALERT(MEU:isFlCancKey)                       !
  632.     ME_Edit()                                    !   Edit the file
  633.     CASE KEYCODE()                               !   Process keystrokes
  634.       OF MEU:isFlCancKey                         !     Cancel
  635.         IF MED:bbHasChanged                      !
  636.           IF NOT ME_Confirm(eLoseChanges, 0)     !
  637.             CYCLE                                !
  638.         . .                                      !
  639.         BREAK                                    !
  640.       OF MEU:isFlSaveKey                         !   Save
  641.         DO SaveFile                              !
  642.        BREAK                                     !
  643.   . .                                            ! End loop
  644.   DO Quit                                        ! Clean-up and exit
  645.  
  646. !──────────────────────────────────────────────────────────────────────────
  647. SaveFile     ROUTINE      ! Save edit buffer to file and quit
  648. !──────────────────────────────────────────────────────────────────────────
  649.   Junk# = ME_SaveASCII(sName, 0, MED:usCharacters-1)
  650.  
  651. !──────────────────────────────────────────────────────────────────────────
  652. Quit         ROUTINE      ! Common exit code
  653. !──────────────────────────────────────────────────────────────────────────
  654.   ME_Done()                                      ! Deallocate memory
  655.   CLOSE(wScreen)                                 ! Close screen
  656.   RETURN
  657.  
  658.